<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>博客管理</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.5.0/dist/semantic.min.css">
    <link rel="stylesheet" href="/static/css/me.css">
</head>
<body>
<!--导航-->
<nav th:replace="admin/_fragments :: menu(1)" class="ui inverted attached segment m-padded-tb-mini m-shadow">
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header item">博客管理</h2>
            <a th:href="@{admin/index.html}" href="#" class="m-item item m-mobile-hide"><i class="home icon"></i>首页</a>
            <a th:href="@{admin/types.html}" href="#" class="m-item item m-mobile-hide"><i class="home icon"></i>分类</a>
            <a th:href="@{admin/tags.html}" href="#" class="m-item item m-mobile-hide"><i class="tags icon"></i>标签</a>
            <a th:href="@{admin/archives.html}" href="#" class="m-item item m-mobile-hide"><i class="clone icon"></i>归档</a>

            <div class="right m-item  m-mobile-hide menu">
                <div class="ui dropdown item">
                    <div class="text">
                        <img src="https://unsplash.it/100/100?image=1005" alt="" class="ui avatar image">
                        王建凯
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a class="item">注销</a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <a href="#" class="ui menu toggle black icon button m-top-right m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>
<div class="ui attached pointing menu">
    <div class="ui container">
        <div class="right menu">
            <a th:href="@{/admin/blogs/input}" href="#" class="item">发布</a>
            <a th:href="@{/admin/blogs}" class="active item">列表</a>
        </div>

    </div>

</div>
<!--中间内容-->
<div class="m-container m-padded-tb-big">
    <div class="ui container">

        <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
            <i class="close icon"></i>
            <div class="header">提示:</div>
            <p th:text="${message}">恭喜:操作成功</p>
        </div>

        <div class="ui secondary segment form">
            <input type="hidden" name="page"><!--动态的赋值，让上一页和下一页能够带着上面的选择的分类名和标签名-->
            <div class="inline fields">
                <div class="field">
                    <input type="text" name="title" placeholder="标题">
                </div>
                <div class="field">
                    <div class="ui selection dropdown">
                        <input type="hidden" name="typeId">
                        <i class="dropdown icon"></i>
                        <div class="default text">分类</div>
                        <div class="menu">
                            <div th:each="type : ${types}" th:data-value="${type.id}" th:text="${type.name}" class="item"
                                 data-value="1">错误日志
                            </div>
<!--                            &lt;!&ndash;/*&ndash;&gt;-->
<!--                            <div class="item" data-value="2">开发者手册</div>-->
<!--                            &lt;!&ndash;*/&ndash;&gt;-->
                        </div>
                    </div>
                </div>
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" name="recommend " id="recommend">
                        <label for="recommend">推荐</label>
                    </div>
                </div>
                <div class="field">
                    <button type="button" id="search-btn" class="ui mini teal basic button">
                        <i class="search icon"></i>搜索
                    </button>
                </div>
                <div class="field">
                    <a th:href="@{/admin/blogs/input}"  href="#" class="ui mini right floated teal basic button">新增</a>
                </div>
            </div>
            </form>

            <div id="table-container">
                <table th:fragment="blogList" class="ui compact table">
                    <thead>
                    <tr>
                        <th></th>
                        <th>标题</th>
                        <th>类型</th>
                        <th>推荐</th>
                        <th>发布</th>
                        <th>更新时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <!--content拿到blog列表，然后拿一个bolg列表进行循环-->
                    <tr th:each="blog,iserStat : ${page.content}">
                        <td th:text="${iserStat.count}">1</td>
                        <td th:text="${blog.title}">刻意练习清单</td>
                        <td th:text="${blog.type.name}">认识升级</td>
                        <td th:text="${blog.recommend} ? '是':'否'">是</td>
                        <td th:text="${blog.published} ? '发布':'草稿'">是</td>
                        <td th:text="${#dates.format(blog.updateTime, 'yyyy-MM-dd HH:mm')}">2022-3-2 09:14</td>
                        <td>
                            <a th:href="@{/admin/blogs/{id}/input(id=${blog.id})}" href="#"
                               class="ui mini teal basic button">编辑</a>
                            <a th:href="@{/admin/blogs/{id}/delete(id=${blog.id})}" href="#"
                               class="ui mini teal basic button">删除</a>
                        </td>
                    </tr>
                    </tbody>
                    <tfoot>
                    <tr>
                        <th colspan="6">
                            <!--                        <div class="ui pagination menu">-->
                            <!--                            <a class="icon item">-->
                            <!--                                <i class="left chevron icon"></i>-->
                            <!--                            </a>-->
                            <!--                            <a class="item">1</a>-->
                            <!--                            <a class="item">2</a>-->
                            <!--                            <a class="item">3</a>-->
                            <!--                            <a class="item">4</a>-->
                            <!--                            <a class="icon item">-->
                            <!--                                <i class="right chevron icon"></i>-->
                            <!--                            </a>-->
                            <!--                        </div>-->
                            <div th:if="${page.totalPages}>1" class="ui pagination menu">
                                <a onclick="page(this)" th:attr="data-page=${page.number}-1"
                                   th:unless="${page.first}" class="icon item">
                                    <i class="left chevron icon">上一页</i></a>
                                <a onclick="page(this)" th:attr="data-page=${page.number}+1"
                                   th:unless="${page.last}" class="icon item">
                                    下一页<i class="right chevron icon"></i></a>
                            </div>

                        </th>
                    </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>
</div>
<!--底部-->
<footer th:replace="admin/_fragments :: footer" class="ui inverted vertical segment m-padded-tb-massive">
    <div class="ui center aligned container">
        <div class="ui inverted divided stackable grid">
            <div class="three wide column">
                <div class="item">
                    <img src="/static/images/ewm.jpg" class="ui centered rounded image" alt=""
                         style="width:170px">
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                    <a href="#" class="item">用户故事</a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header">最新博客</h4>
                <div class="ui inverted link list">
                    <p>最新微博最新微博最新微博最新微博最新微博最新微博最新微博最新微博最新微博最新微博</p>
                </div>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-thin">jkdasjfkldajlkasjfkajd</p>
    </div>
</footer>

<!--/*/<th:block th:replace="admin/_fragments :: script">/*/-->
<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>
<!--/*/</th:block>/*/-->

<script>
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });
    $('.ui.dropdown').dropdown({
        on: 'hover'
    });

    //消息提示关闭初始化
    $('.message .close')
        .on('click', function () {
            $(this)
                .closest('.message')
                .transition('fade');
        });

    function page(obj) {
        $("[name='page']").val($(obj).data("page"));/*获取自定义的值，拿到page-data中的值*/
        loaddate();

    }

    $("#search-btn").click(function () {
        loaddate();
    })

    function loaddate() {
        $("#table-container").load(/*[[@{/admin/blogs/search}]]*/"/admin/blogs/search", {
            title: $("[name='title']").val(),
            typeId: $("[name='recommend']").prop('checked'),
            page: $("[name='page']").val()
        });
    }
</script>
</body>
</html>